package com.springclouddemo.rabbitmq.controller;

import com.springclouddemo.rabbitmq.SimpleProducer;
import com.springclouddemo.rabbitmq.config.RabbitConfig;
import com.springclouddemo.rabbitmq.config.TestDto;
import com.springclouddemo.rabbitmq.demo1.RabbitProducer;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RequestMapping(value = "/rabbitmq/")
@RestController
@Api(tags="rabbitmq provicder | rabbitmq消息提供者")
public class TestController {
    @GetMapping("/sendDirectMessage")
    public String sendDirectMessage() {
        String messageId = String.valueOf(UUID.randomUUID());
        String messageData = "test message, hello!";
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String,Object> map=new HashMap<>();
        map.put("messageId",messageId);
        map.put("messageData",messageData);
        map.put("createTime",createTime);
        //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
//        rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);
        return "ok";
    }

    @Autowired
    private SimpleProducer simpleProducer;
    @GetMapping("/demo1/sendSimple")
    public  String sendSimple(){
        simpleProducer.sendMessage(RabbitConfig.DEMO_QUEUE,"First message in spring boot.");
        return "ok";
    }
    @GetMapping("/demo1/sendObject")
    public  String sendObject(){
        TestDto dto=new TestDto();
        dto.setId(10000);
        dto.setName("strstest");
        simpleProducer.sendObjMessage(dto);
        return "ok";
    }

    @Autowired
    private RabbitProducer rabbitProducer;
    @GetMapping("/demo1/sendDemoQueue")
    public Object sendDemoQueue() {
        rabbitProducer.sendDemoQueue();
        return "success";
    }
    @GetMapping("/demo1/sendFanout")
    public Object sendFanout() {
        rabbitProducer.sendFanout();
        return "success";
    }

    @GetMapping("/demo1/sendTopicTopicAB")
    public Object sendTopicTopicAB() {
        rabbitProducer.sendTopicTopicAB();
        return "success";
    }

    @GetMapping("/demo1/sendTopicTopicB")
    public Object sendTopicTopicB() {
        rabbitProducer.sendTopicTopicB();
        return "success";
    }

    @GetMapping("/demo1/sendTopicTopicBC")
    public Object sendTopicTopicBC() {
        rabbitProducer.sendTopicTopicBC();
        return "success";
    }
}
